﻿
<?php
	include("php/session.php");
	include("php/error.php");
	include("php/bbcode.php");
	include("dao/ConteudoDAO.class.php");
	include("dao/UsuarioDAO.class.php");
	include("dao/CategoriasDAO.class.php");
	
	#set_error_handler("customError");
	
	$idconteudo_get = $_GET['append'];
	
	$categoriasdao = new CategoriasDAO();
	$categorias = $categoriasdao->buscar();
	
	$conteudodao = new ConteudoDAO();
	$conteudo = $conteudodao->buscarConteudo($idconteudo_get);
	
	$categoriaModel = $categoriasdao->buscarCategoria($conteudo->getFk_idCategorias());
	$categoria_get = $categoriaModel->getNome();
	
	$usuariodao = new UsuarioDAO();
	$usuario = $usuariodao->buscar($conteudo->getFk_idUsuario());
	
	$arrTags = array();
	$arrTags = $conteudodao->buscarTags($idconteudo_get);
	
	$str_conteudo = htmlspecialchars($conteudo->getConteudo());
	$str_conteudo = bbcode($str_conteudo);
	//$str_conteudo = nl2br($str_conteudo);
	
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Chimera</title>
<link rel="stylesheet" type="text/css" href="css/css.css">
<link rel="stylesheet" type="text/css" href="css/prettify.css">
<link rel="stylesheet" type="text/css" href="css/modal.css">
<script src="js/jquery-1.11.1.js"></script>
<script src="js/campos.js"></script>
<script src="js/run_prettify.js"></script>
<script src="js/modal.js"></script>
</head>

<body>
	
    <div id="fb-root"></div>
	<script>(function(d, s, id) {
				  var js, fjs = d.getElementsByTagName(s)[0];
				  if (d.getElementById(id)) return;
				  js = d.createElement(s); js.id = id;
				  js.src = "//connect.facebook.net/pt_BR/sdk.js#xfbml=1&version=v2.0";
				  fjs.parentNode.insertBefore(js, fjs);
				}(document, 'script', 'facebook-jssdk'));
    </script>
    
	<main>
    
   	  <header>
          <div class="container">
          	<div class="topoSuperior">
              <a href="inicio.php"><span class="logo"></span></a>
              <input type="text" class="pesquisaTopo" placeholder="Faça sua pesquisa..." />
              <select class="categoriasPesquisa">
                  <?php foreach($categorias as $categoria): ?>
                      <option value="<?= $categoria->getIdCategorias();?>"><?= $categoria->getNome();?></option>
                  <?php endforeach;?>
              </select>
              <span class="logout">
                  <a href="php/logout.php"></a>
              </span>
              <span class="sessionNome"><?= $_SESSION['nome'] ?></span>
          	</div>
            <div class="topoInferior">
            	<div class="menuTopo">
                	<span class="menuPost">Menu</span>
                    <span class="config">Opções</span>
                    <a href="#dialogNew" name="modal" class="new">Novo</span>
                    <a href="inicio.php" class="home">Início</a>
                    <a href="posts.php?append=<?=$conteudo->getFk_idCategorias()?>&match=<?= $categoria_get?>" class="menuPosts"><?= $categoria_get?></a>
                </div>
            </div>
          </div>
      </header>
        
   	  <section class="post">
        
        <div class="container">
            
            <div class="junteLeft">
            	
                <ul class="opcoes">
                    <li>
                    <a href="controller/remove.php?append=<?= $idconteudo_get?>&appendcat=<?=$conteudo->getFk_idCategorias()?>&match=<?= $categoria_get?>&action=1445" class="excluirPost">excluir</a>
                    </li>
                    <li>
                        <a href="editar.php?append=<?= $idconteudo_get?>&appendcat=<?=$conteudo->getFk_idCategorias()?>&match=<?= $categoria_get?>" class="editarPost">editar</a>
                    </li>
                </ul>
                
                <ul class="menu">
                    <?php foreach($categorias as $categoria): ?>
                    
                        <li>
                            <a href="posts.php?append=<?= $categoria->getIdCategorias();?>&match=<?= $categoria->getNome();?>">
                                <?= $categoria->getNome();?>
                            </a>
                        </li>
                    
                    <?php endforeach;?>
                
                </ul>
                
            </div>
            
            <div class="junteRight">
            	<h3 class="menuTitulo"><?= $conteudo->getAssunto()?></h3>
                <div class="postNews">
                	<div class="postConteudo"><p><?=$str_conteudo?></p></div>
                </div>
                <div class="tagsPost">
                    <ul>
                        <li>tags &nbsp;</li>
						<?php foreach($arrTags as $i => $tag):?>
                            <li><?= $tag?></li>     	
                        <?php endforeach;?>
                    </ul>
                    <?php
						$endereco = $_SERVER ['REQUEST_URI'];
					?>
                </div>
                <div class="fb-comments" data-width="700" data-href="<?= $endereco?>" data-numposts="5" data-colorscheme="light"></div>
            </div>
            
      	</div>
      
      </section>
      
    </main>
    
    <div id="boxes">
        <div id="dialogNew" class="window shadow">
            <span class="close">X</span>
            <form class="formNovaNew" 
                action="controller/add.php?action=3445" method="post">
                	
                    <input type="text" class="inputAssunto" placeholder="Assunto" name="assunto"/>
                    <select class="inputCategorias" name="categoria">
						<?php foreach($categorias as $categoria): ?>
                            <option value="<?= $categoria->getIdCategorias();?>"><?= $categoria->getNome();?></option>
                        <?php endforeach;?>
                    </select>
                    <textarea id="mybox" class="inputConteudo" placeholder="Escreva o texto aqui" name="conteudo"></textarea>
                    
                    <a href="#" class="adicionarCampo">+</a>
                    
                    <div class="divTags">
                    	<input class="inputTags" name="tags[]" placeholder="Insira tags para pesquisa..."/>
                    </div>
                    
                    <input class="buttonEnviar" type="submit" value="Enviar" />
                    
                </form>
        </div>

        <div id="mask"></div>
    </div>
    
</body>
</html>